<!--
 * @Author: MarioGo
 * @Date: 2021-11-20 14:30:30
 * @LastEditTime: 2021-11-20 14:30:31
 * @LastEditors: MarioGo
 * @Description: 文件描述
 * @FilePath: /zheye/src/components/ Loader.vue
 * 可以输入预定的版权声明、个性签名、空行等
-->
<template>
  <!-- 使用teleport传送门挂载组件,挂载在id值为back的元素上 -->
  <teleport to="#back">
    <!-- background-color属性值在vue中通过backgroundColor表示 -->
    <div
      class="d-flex justify-content-center align-items-center h-100 w-100 loading-container"
      :style="{ backgroundColor: background || '' }"
    >
      <div class="loading-content">
        <div class="spinner-border text-primary" style="width: 3rem; height: 3rem" role="status">
          <span class="visually-hidden">{{ text || '正在加载中' }}</span>
        </div>
        <p v-if="text" class="text-primary">{{ text }}</p>
      </div>
    </div>
  </teleport>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import useDOMCreate from '../hooks/useDOMCreate';

export default defineComponent({
  name: 'Loader',
  props: {
    text: {
      type: String,
    },
    background: {
      type: String,
    },
  },
  setup() {
    // 创建teleport组件挂载的节点
    useDOMCreate('back');
  },
});
</script>

<style>
/* 设置div的遮罩层的样式*/
.loading-container {
  background: rgba(255, 255, 255, 0.5);
  /* z轴方向显示的优先级 */
  z-index: 100;
  position: fixed;
  top: 0;
  left: 0;
}
.loading-container {
  text-align: center;
}
</style>
